using System;
using System.Drawing;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Configuration;
using System.IO;
using DaBCoS.Engine;

namespace DaBCoS {
	/// <summary>
	/// Summary description for frmMain.
	/// </summary>
	public class FormMain : System.Windows.Forms.Form {
		private System.Windows.Forms.ToolBar tbMain;
		private System.Windows.Forms.ToolBarButton tbbConnect;
		private System.Windows.Forms.ImageList ilToolbar;
		private System.Windows.Forms.ToolBarButton tbbSeparator1;
		private System.Windows.Forms.StatusBar sbMain;
		private System.Windows.Forms.Timer tmrCleanStatusBar;
		private System.Windows.Forms.ToolBarButton tbbDisconnect;
		private System.Windows.Forms.StatusBarPanel sbpMessages;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.ToolBarButton tbbConnect2;
		private System.Windows.Forms.ToolBarButton tbbDisconnect2;
		private System.Windows.Forms.ToolBarButton tbbSeparator2;
		private System.Windows.Forms.ToolBarButton tbbCompare;
		private System.Windows.Forms.ToolBarButton tbbDatabase;
		private System.Windows.Forms.ToolBarButton tbbDatabase2;
		private System.Windows.Forms.Splitter splitter1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Splitter splitter2;
		private System.Windows.Forms.ToolBarButton tbbSynchronize;
		private System.Windows.Forms.ImageList ilMisc;
		private System.Windows.Forms.ColumnHeader columnHeader1;
		private System.Windows.Forms.ColumnHeader columnHeader2;
		private System.Windows.Forms.ColumnHeader columnHeader3;
		private System.Windows.Forms.ColumnHeader columnHeader4;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TabControl tcMain;
		private System.Windows.Forms.TabPage tpTables;
		private System.Windows.Forms.ListView lvTables;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.TabPage tpFunctions;
		private System.Windows.Forms.ListView lvFunctions;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TabPage tpViews;
		private System.Windows.Forms.ListView lvViews;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.TabPage tpStoredProcs;
		private System.Windows.Forms.ListView lvProcedures;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.ColumnHeader chDatabaseA;
		private System.Windows.Forms.ColumnHeader chState;
		private System.Windows.Forms.ColumnHeader chAction;
		private System.Windows.Forms.ColumnHeader chDatabaseB;
		private System.Windows.Forms.ColumnHeader columnHeader9;
		private System.Windows.Forms.ColumnHeader columnHeader10;
		private System.Windows.Forms.ColumnHeader columnHeader11;
		private System.Windows.Forms.ColumnHeader columnHeader12;
		private System.Windows.Forms.ColumnHeader columnHeader5;
		private System.Windows.Forms.ColumnHeader columnHeader6;
		private System.Windows.Forms.ColumnHeader columnHeader7;
		private System.Windows.Forms.ColumnHeader columnHeader8;
		private System.Windows.Forms.ColumnHeader columnHeader13;
		private System.Windows.Forms.ColumnHeader columnHeader14;
		private System.Windows.Forms.ColumnHeader columnHeader15;
		private System.Windows.Forms.ColumnHeader columnHeader16;
		private System.Windows.Forms.PictureBox pbUser1;
		private System.Windows.Forms.PictureBox pbTable1;
		private System.Windows.Forms.PictureBox pbTable2;
		private System.Windows.Forms.PictureBox pbUser2;
		private System.Windows.Forms.PictureBox pbDB2;
		private System.Windows.Forms.PictureBox pbDB1;
		private System.Windows.Forms.Label lblUserSecond;
		private System.Windows.Forms.Label lblUserFirst;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.ProgressBar pbState;
		private System.Windows.Forms.Label lblDBSecond;
		private System.Windows.Forms.Label lblServerSecond;
		private System.Windows.Forms.Label lblDBFirst;
		private System.Windows.Forms.Label lblServerFirst;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.ListBox lbLog;
		private System.Windows.Forms.Label lblSource2;
		private System.Windows.Forms.Label lblSource1;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.MainMenu mmMain;
		private System.Windows.Forms.MenuItem menuItem3;
		private System.Windows.Forms.MenuItem menuItem4;
		private System.Windows.Forms.MenuItem menuItem5;
		private System.Windows.Forms.MenuItem menuItem6;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;

		private FormAbout wndAbout = null;
		private FormDetail wndDatabaseInfo = null;
		private FormSelectDatabase wndDatabaseSelection = null;
		private FormLogin wndLoginInfo = null;

		private SqlServer databaseLeft;
		private SqlServer databaseRight;

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent() {
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormMain));
			this.tbMain = new System.Windows.Forms.ToolBar();
			this.tbbConnect = new System.Windows.Forms.ToolBarButton();
			this.tbbDisconnect = new System.Windows.Forms.ToolBarButton();
			this.tbbDatabase = new System.Windows.Forms.ToolBarButton();
			this.tbbSeparator1 = new System.Windows.Forms.ToolBarButton();
			this.tbbConnect2 = new System.Windows.Forms.ToolBarButton();
			this.tbbDisconnect2 = new System.Windows.Forms.ToolBarButton();
			this.tbbDatabase2 = new System.Windows.Forms.ToolBarButton();
			this.tbbSeparator2 = new System.Windows.Forms.ToolBarButton();
			this.tbbCompare = new System.Windows.Forms.ToolBarButton();
			this.tbbSynchronize = new System.Windows.Forms.ToolBarButton();
			this.ilToolbar = new System.Windows.Forms.ImageList(this.components);
			this.sbMain = new System.Windows.Forms.StatusBar();
			this.sbpMessages = new System.Windows.Forms.StatusBarPanel();
			this.tmrCleanStatusBar = new System.Windows.Forms.Timer(this.components);
			this.splitter1 = new System.Windows.Forms.Splitter();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.button2 = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.pbUser1 = new System.Windows.Forms.PictureBox();
			this.pbTable1 = new System.Windows.Forms.PictureBox();
			this.pbTable2 = new System.Windows.Forms.PictureBox();
			this.pbUser2 = new System.Windows.Forms.PictureBox();
			this.pbDB2 = new System.Windows.Forms.PictureBox();
			this.pbDB1 = new System.Windows.Forms.PictureBox();
			this.lblUserSecond = new System.Windows.Forms.Label();
			this.lblUserFirst = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.pbState = new System.Windows.Forms.ProgressBar();
			this.lblDBSecond = new System.Windows.Forms.Label();
			this.lblServerSecond = new System.Windows.Forms.Label();
			this.lblSource2 = new System.Windows.Forms.Label();
			this.lblDBFirst = new System.Windows.Forms.Label();
			this.lblServerFirst = new System.Windows.Forms.Label();
			this.lblSource1 = new System.Windows.Forms.Label();
			this.splitter2 = new System.Windows.Forms.Splitter();
			this.ilMisc = new System.Windows.Forms.ImageList(this.components);
			this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.tcMain = new System.Windows.Forms.TabControl();
			this.tpTables = new System.Windows.Forms.TabPage();
			this.lvTables = new System.Windows.Forms.ListView();
			this.chDatabaseA = new System.Windows.Forms.ColumnHeader();
			this.chState = new System.Windows.Forms.ColumnHeader();
			this.chAction = new System.Windows.Forms.ColumnHeader();
			this.chDatabaseB = new System.Windows.Forms.ColumnHeader();
			this.label8 = new System.Windows.Forms.Label();
			this.tpFunctions = new System.Windows.Forms.TabPage();
			this.lvFunctions = new System.Windows.Forms.ListView();
			this.columnHeader9 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader10 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader11 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader12 = new System.Windows.Forms.ColumnHeader();
			this.label4 = new System.Windows.Forms.Label();
			this.tpViews = new System.Windows.Forms.TabPage();
			this.lvViews = new System.Windows.Forms.ListView();
			this.columnHeader5 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader6 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader7 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader8 = new System.Windows.Forms.ColumnHeader();
			this.label6 = new System.Windows.Forms.Label();
			this.tpStoredProcs = new System.Windows.Forms.TabPage();
			this.lvProcedures = new System.Windows.Forms.ListView();
			this.columnHeader13 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader14 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader15 = new System.Windows.Forms.ColumnHeader();
			this.columnHeader16 = new System.Windows.Forms.ColumnHeader();
			this.label5 = new System.Windows.Forms.Label();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.lbLog = new System.Windows.Forms.ListBox();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.menuItem4 = new System.Windows.Forms.MenuItem();
			this.menuItem5 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.menuItem6 = new System.Windows.Forms.MenuItem();
			this.mmMain = new System.Windows.Forms.MainMenu();
			((System.ComponentModel.ISupportInitialize)(this.sbpMessages)).BeginInit();
			this.groupBox2.SuspendLayout();
			this.groupBox1.SuspendLayout();
			this.tcMain.SuspendLayout();
			this.tpTables.SuspendLayout();
			this.tpFunctions.SuspendLayout();
			this.tpViews.SuspendLayout();
			this.tpStoredProcs.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.SuspendLayout();
			// 
			// tbMain
			// 
			this.tbMain.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
			this.tbMain.AutoSize = false;
			this.tbMain.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																					  this.tbbConnect,
																					  this.tbbDisconnect,
																					  this.tbbDatabase,
																					  this.tbbSeparator1,
																					  this.tbbConnect2,
																					  this.tbbDisconnect2,
																					  this.tbbDatabase2,
																					  this.tbbSeparator2,
																					  this.tbbCompare,
																					  this.tbbSynchronize});
			this.tbMain.ButtonSize = new System.Drawing.Size(65, 36);
			this.tbMain.DropDownArrows = true;
			this.tbMain.ImageList = this.ilToolbar;
			this.tbMain.Name = "tbMain";
			this.tbMain.ShowToolTips = true;
			this.tbMain.Size = new System.Drawing.Size(712, 39);
			this.tbMain.TabIndex = 0;
			this.tbMain.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.tbMain_ButtonClick);
			// 
			// tbbConnect
			// 
			this.tbbConnect.ImageIndex = 0;
			this.tbbConnect.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
			this.tbbConnect.Text = "Connect";
			// 
			// tbbDisconnect
			// 
			this.tbbDisconnect.Enabled = false;
			this.tbbDisconnect.ImageIndex = 1;
			this.tbbDisconnect.Text = "Disconnect";
			// 
			// tbbDatabase
			// 
			this.tbbDatabase.Enabled = false;
			this.tbbDatabase.ImageIndex = 2;
			this.tbbDatabase.Text = "Database";
			// 
			// tbbSeparator1
			// 
			this.tbbSeparator1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// tbbConnect2
			// 
			this.tbbConnect2.ImageIndex = 3;
			this.tbbConnect2.Style = System.Windows.Forms.ToolBarButtonStyle.DropDownButton;
			this.tbbConnect2.Text = "Connect";
			// 
			// tbbDisconnect2
			// 
			this.tbbDisconnect2.Enabled = false;
			this.tbbDisconnect2.ImageIndex = 4;
			this.tbbDisconnect2.Text = "Disconnect";
			// 
			// tbbDatabase2
			// 
			this.tbbDatabase2.Enabled = false;
			this.tbbDatabase2.ImageIndex = 5;
			this.tbbDatabase2.Text = "Database";
			// 
			// tbbSeparator2
			// 
			this.tbbSeparator2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// tbbCompare
			// 
			this.tbbCompare.Enabled = false;
			this.tbbCompare.ImageIndex = 6;
			this.tbbCompare.Text = "Compare";
			// 
			// tbbSynchronize
			// 
			this.tbbSynchronize.Enabled = false;
			this.tbbSynchronize.ImageIndex = 7;
			this.tbbSynchronize.Text = "Synchronize";
			// 
			// ilToolbar
			// 
			this.ilToolbar.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
			this.ilToolbar.ImageSize = new System.Drawing.Size(16, 16);
			this.ilToolbar.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilToolbar.ImageStream")));
			this.ilToolbar.TransparentColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(0)), ((System.Byte)(234)));
			// 
			// sbMain
			// 
			this.sbMain.Location = new System.Drawing.Point(0, 488);
			this.sbMain.Name = "sbMain";
			this.sbMain.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
																					  this.sbpMessages});
			this.sbMain.ShowPanels = true;
			this.sbMain.Size = new System.Drawing.Size(712, 16);
			this.sbMain.TabIndex = 2;
			// 
			// sbpMessages
			// 
			this.sbpMessages.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
			this.sbpMessages.Width = 696;
			// 
			// tmrCleanStatusBar
			// 
			this.tmrCleanStatusBar.Interval = 1000;
			this.tmrCleanStatusBar.Tick += new System.EventHandler(this.tmrCleanStatusBar_Tick);
			// 
			// splitter1
			// 
			this.splitter1.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.splitter1.Location = new System.Drawing.Point(0, 384);
			this.splitter1.Name = "splitter1";
			this.splitter1.Size = new System.Drawing.Size(712, 4);
			this.splitter1.TabIndex = 5;
			this.splitter1.TabStop = false;
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.button2,
																					this.button1,
																					this.pbUser1,
																					this.pbTable1,
																					this.pbTable2,
																					this.pbUser2,
																					this.pbDB2,
																					this.pbDB1,
																					this.lblUserSecond,
																					this.lblUserFirst,
																					this.label3,
																					this.pbState,
																					this.lblDBSecond,
																					this.lblServerSecond,
																					this.lblSource2,
																					this.lblDBFirst,
																					this.lblServerFirst,
																					this.lblSource1});
			this.groupBox2.Dock = System.Windows.Forms.DockStyle.Right;
			this.groupBox2.Location = new System.Drawing.Point(536, 39);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(176, 345);
			this.groupBox2.TabIndex = 16;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "Connections";
			// 
			// button2
			// 
			this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.button2.Location = new System.Drawing.Point(48, 264);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(85, 23);
			this.button2.TabIndex = 33;
			this.button2.Text = "Save Session";
			this.button2.Visible = false;
			// 
			// button1
			// 
			this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.button1.Location = new System.Drawing.Point(46, 120);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(85, 23);
			this.button1.TabIndex = 32;
			this.button1.Text = "Save Session";
			this.button1.Visible = false;
			// 
			// pbUser1
			// 
			this.pbUser1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.pbUser1.Location = new System.Drawing.Point(3, 64);
			this.pbUser1.Name = "pbUser1";
			this.pbUser1.Size = new System.Drawing.Size(16, 16);
			this.pbUser1.TabIndex = 31;
			this.pbUser1.TabStop = false;
			// 
			// pbTable1
			// 
			this.pbTable1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.pbTable1.Location = new System.Drawing.Point(3, 88);
			this.pbTable1.Name = "pbTable1";
			this.pbTable1.Size = new System.Drawing.Size(16, 16);
			this.pbTable1.TabIndex = 30;
			this.pbTable1.TabStop = false;
			// 
			// pbTable2
			// 
			this.pbTable2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.pbTable2.Location = new System.Drawing.Point(3, 207);
			this.pbTable2.Name = "pbTable2";
			this.pbTable2.Size = new System.Drawing.Size(16, 16);
			this.pbTable2.TabIndex = 29;
			this.pbTable2.TabStop = false;
			// 
			// pbUser2
			// 
			this.pbUser2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.pbUser2.Location = new System.Drawing.Point(3, 231);
			this.pbUser2.Name = "pbUser2";
			this.pbUser2.Size = new System.Drawing.Size(16, 16);
			this.pbUser2.TabIndex = 28;
			this.pbUser2.TabStop = false;
			// 
			// pbDB2
			// 
			this.pbDB2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.pbDB2.Location = new System.Drawing.Point(3, 183);
			this.pbDB2.Name = "pbDB2";
			this.pbDB2.Size = new System.Drawing.Size(16, 16);
			this.pbDB2.TabIndex = 27;
			this.pbDB2.TabStop = false;
			// 
			// pbDB1
			// 
			this.pbDB1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.pbDB1.Location = new System.Drawing.Point(3, 40);
			this.pbDB1.Name = "pbDB1";
			this.pbDB1.Size = new System.Drawing.Size(16, 16);
			this.pbDB1.TabIndex = 26;
			this.pbDB1.TabStop = false;
			// 
			// lblUserSecond
			// 
			this.lblUserSecond.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.lblUserSecond.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblUserSecond.Location = new System.Drawing.Point(20, 209);
			this.lblUserSecond.Name = "lblUserSecond";
			this.lblUserSecond.Size = new System.Drawing.Size(152, 16);
			this.lblUserSecond.TabIndex = 25;
			// 
			// lblUserFirst
			// 
			this.lblUserFirst.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.lblUserFirst.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblUserFirst.Location = new System.Drawing.Point(20, 66);
			this.lblUserFirst.Name = "lblUserFirst";
			this.lblUserFirst.Size = new System.Drawing.Size(152, 16);
			this.lblUserFirst.TabIndex = 24;
			// 
			// label3
			// 
			this.label3.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.label3.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label3.Location = new System.Drawing.Point(3, 310);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(170, 16);
			this.label3.TabIndex = 23;
			this.label3.Text = "Current operation:";
			// 
			// pbState
			// 
			this.pbState.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.pbState.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.pbState.Location = new System.Drawing.Point(3, 326);
			this.pbState.Name = "pbState";
			this.pbState.Size = new System.Drawing.Size(170, 16);
			this.pbState.Step = 1;
			this.pbState.TabIndex = 22;
			// 
			// lblDBSecond
			// 
			this.lblDBSecond.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.lblDBSecond.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblDBSecond.Location = new System.Drawing.Point(20, 233);
			this.lblDBSecond.Name = "lblDBSecond";
			this.lblDBSecond.Size = new System.Drawing.Size(152, 16);
			this.lblDBSecond.TabIndex = 21;
			// 
			// lblServerSecond
			// 
			this.lblServerSecond.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.lblServerSecond.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblServerSecond.Location = new System.Drawing.Point(20, 185);
			this.lblServerSecond.Name = "lblServerSecond";
			this.lblServerSecond.Size = new System.Drawing.Size(152, 16);
			this.lblServerSecond.TabIndex = 20;
			// 
			// lblSource2
			// 
			this.lblSource2.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.lblSource2.BackColor = System.Drawing.SystemColors.ControlDark;
			this.lblSource2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblSource2.Location = new System.Drawing.Point(3, 159);
			this.lblSource2.Name = "lblSource2";
			this.lblSource2.Size = new System.Drawing.Size(168, 16);
			this.lblSource2.TabIndex = 19;
			this.lblSource2.Text = "Source 2";
			// 
			// lblDBFirst
			// 
			this.lblDBFirst.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.lblDBFirst.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblDBFirst.Location = new System.Drawing.Point(20, 90);
			this.lblDBFirst.Name = "lblDBFirst";
			this.lblDBFirst.Size = new System.Drawing.Size(152, 16);
			this.lblDBFirst.TabIndex = 18;
			// 
			// lblServerFirst
			// 
			this.lblServerFirst.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.lblServerFirst.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblServerFirst.Location = new System.Drawing.Point(20, 42);
			this.lblServerFirst.Name = "lblServerFirst";
			this.lblServerFirst.Size = new System.Drawing.Size(152, 16);
			this.lblServerFirst.TabIndex = 17;
			// 
			// lblSource1
			// 
			this.lblSource1.BackColor = System.Drawing.SystemColors.ControlDark;
			this.lblSource1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblSource1.Location = new System.Drawing.Point(3, 16);
			this.lblSource1.Name = "lblSource1";
			this.lblSource1.Size = new System.Drawing.Size(168, 16);
			this.lblSource1.TabIndex = 16;
			this.lblSource1.Text = "Source 1";
			// 
			// splitter2
			// 
			this.splitter2.Dock = System.Windows.Forms.DockStyle.Right;
			this.splitter2.Location = new System.Drawing.Point(532, 39);
			this.splitter2.Name = "splitter2";
			this.splitter2.Size = new System.Drawing.Size(4, 345);
			this.splitter2.TabIndex = 12;
			this.splitter2.TabStop = false;
			// 
			// ilMisc
			// 
			this.ilMisc.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
			this.ilMisc.ImageSize = new System.Drawing.Size(16, 16);
			this.ilMisc.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilMisc.ImageStream")));
			this.ilMisc.TransparentColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(0)), ((System.Byte)(234)));
			// 
			// columnHeader1
			// 
			this.columnHeader1.Text = "Database 1";
			this.columnHeader1.Width = 200;
			// 
			// columnHeader2
			// 
			this.columnHeader2.Text = "State";
			this.columnHeader2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// columnHeader3
			// 
			this.columnHeader3.Text = "Action";
			this.columnHeader3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// columnHeader4
			// 
			this.columnHeader4.Text = "Database 2";
			this.columnHeader4.Width = 200;
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.tcMain});
			this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.groupBox1.Location = new System.Drawing.Point(0, 39);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(532, 345);
			this.groupBox1.TabIndex = 14;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Database";
			// 
			// tcMain
			// 
			this.tcMain.Appearance = System.Windows.Forms.TabAppearance.FlatButtons;
			this.tcMain.Controls.AddRange(new System.Windows.Forms.Control[] {
																				 this.tpTables,
																				 this.tpFunctions,
																				 this.tpViews,
																				 this.tpStoredProcs});
			this.tcMain.Dock = System.Windows.Forms.DockStyle.Fill;
			this.tcMain.HotTrack = true;
			this.tcMain.Location = new System.Drawing.Point(3, 17);
			this.tcMain.Name = "tcMain";
			this.tcMain.SelectedIndex = 0;
			this.tcMain.Size = new System.Drawing.Size(526, 325);
			this.tcMain.TabIndex = 14;
			// 
			// tpTables
			// 
			this.tpTables.Controls.AddRange(new System.Windows.Forms.Control[] {
																				   this.lvTables,
																				   this.label8});
			this.tpTables.Location = new System.Drawing.Point(4, 25);
			this.tpTables.Name = "tpTables";
			this.tpTables.Size = new System.Drawing.Size(518, 296);
			this.tpTables.TabIndex = 0;
			this.tpTables.Text = "Tables";
			// 
			// lvTables
			// 
			this.lvTables.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.lvTables.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																					   this.chDatabaseA,
																					   this.chState,
																					   this.chAction,
																					   this.chDatabaseB});
			this.lvTables.Dock = System.Windows.Forms.DockStyle.Fill;
			this.lvTables.Font = new System.Drawing.Font("Verdana", 8.25F);
			this.lvTables.ForeColor = System.Drawing.SystemColors.WindowText;
			this.lvTables.FullRowSelect = true;
			this.lvTables.GridLines = true;
			this.lvTables.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
			this.lvTables.Location = new System.Drawing.Point(0, 16);
			this.lvTables.MultiSelect = false;
			this.lvTables.Name = "lvTables";
			this.lvTables.Size = new System.Drawing.Size(518, 280);
			this.lvTables.TabIndex = 2;
			this.lvTables.View = System.Windows.Forms.View.Details;
			this.lvTables.Resize += new System.EventHandler(this.lvAll_Resize);
			this.lvTables.DoubleClick += new System.EventHandler(this.lvTables_DoubleClick);
			// 
			// chDatabaseA
			// 
			this.chDatabaseA.Text = "Database 1";
			this.chDatabaseA.Width = 200;
			// 
			// chState
			// 
			this.chState.Text = "State";
			this.chState.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// chAction
			// 
			this.chAction.Text = "Action";
			this.chAction.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// chDatabaseB
			// 
			this.chDatabaseB.Text = "Database 2";
			this.chDatabaseB.Width = 200;
			// 
			// label8
			// 
			this.label8.BackColor = System.Drawing.SystemColors.ControlDark;
			this.label8.Dock = System.Windows.Forms.DockStyle.Top;
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(518, 16);
			this.label8.TabIndex = 3;
			this.label8.Text = "Tables";
			// 
			// tpFunctions
			// 
			this.tpFunctions.Controls.AddRange(new System.Windows.Forms.Control[] {
																					  this.lvFunctions,
																					  this.label4});
			this.tpFunctions.Location = new System.Drawing.Point(4, 25);
			this.tpFunctions.Name = "tpFunctions";
			this.tpFunctions.Size = new System.Drawing.Size(518, 296);
			this.tpFunctions.TabIndex = 3;
			this.tpFunctions.Text = "Functions";
			this.tpFunctions.Visible = false;
			// 
			// lvFunctions
			// 
			this.lvFunctions.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.lvFunctions.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																						  this.columnHeader9,
																						  this.columnHeader10,
																						  this.columnHeader11,
																						  this.columnHeader12});
			this.lvFunctions.Dock = System.Windows.Forms.DockStyle.Fill;
			this.lvFunctions.Font = new System.Drawing.Font("Verdana", 8.25F);
			this.lvFunctions.FullRowSelect = true;
			this.lvFunctions.GridLines = true;
			this.lvFunctions.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
			this.lvFunctions.Location = new System.Drawing.Point(0, 16);
			this.lvFunctions.MultiSelect = false;
			this.lvFunctions.Name = "lvFunctions";
			this.lvFunctions.Size = new System.Drawing.Size(518, 280);
			this.lvFunctions.TabIndex = 4;
			this.lvFunctions.View = System.Windows.Forms.View.Details;
			this.lvFunctions.Resize += new System.EventHandler(this.lvAll_Resize);
			this.lvFunctions.DoubleClick += new System.EventHandler(this.lvFunctions_DoubleClick);
			// 
			// columnHeader9
			// 
			this.columnHeader9.Text = "Database 1";
			this.columnHeader9.Width = 200;
			// 
			// columnHeader10
			// 
			this.columnHeader10.Text = "State";
			this.columnHeader10.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// columnHeader11
			// 
			this.columnHeader11.Text = "Action";
			this.columnHeader11.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// columnHeader12
			// 
			this.columnHeader12.Text = "Database 2";
			this.columnHeader12.Width = 200;
			// 
			// label4
			// 
			this.label4.BackColor = System.Drawing.SystemColors.ControlDark;
			this.label4.Dock = System.Windows.Forms.DockStyle.Top;
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(518, 16);
			this.label4.TabIndex = 5;
			this.label4.Text = "Functions";
			// 
			// tpViews
			// 
			this.tpViews.Controls.AddRange(new System.Windows.Forms.Control[] {
																				  this.lvViews,
																				  this.label6});
			this.tpViews.Location = new System.Drawing.Point(4, 25);
			this.tpViews.Name = "tpViews";
			this.tpViews.Size = new System.Drawing.Size(518, 296);
			this.tpViews.TabIndex = 1;
			this.tpViews.Text = "Views";
			this.tpViews.Visible = false;
			// 
			// lvViews
			// 
			this.lvViews.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.lvViews.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																					  this.columnHeader5,
																					  this.columnHeader6,
																					  this.columnHeader7,
																					  this.columnHeader8});
			this.lvViews.Dock = System.Windows.Forms.DockStyle.Fill;
			this.lvViews.Font = new System.Drawing.Font("Verdana", 8.25F);
			this.lvViews.FullRowSelect = true;
			this.lvViews.GridLines = true;
			this.lvViews.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
			this.lvViews.Location = new System.Drawing.Point(0, 16);
			this.lvViews.MultiSelect = false;
			this.lvViews.Name = "lvViews";
			this.lvViews.Size = new System.Drawing.Size(518, 280);
			this.lvViews.TabIndex = 3;
			this.lvViews.View = System.Windows.Forms.View.Details;
			this.lvViews.Resize += new System.EventHandler(this.lvAll_Resize);
			this.lvViews.DoubleClick += new System.EventHandler(this.lvViews_DoubleClick);
			// 
			// columnHeader5
			// 
			this.columnHeader5.Text = "Database 1";
			this.columnHeader5.Width = 200;
			// 
			// columnHeader6
			// 
			this.columnHeader6.Text = "State";
			this.columnHeader6.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// columnHeader7
			// 
			this.columnHeader7.Text = "Action";
			this.columnHeader7.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// columnHeader8
			// 
			this.columnHeader8.Text = "Database 2";
			this.columnHeader8.Width = 200;
			// 
			// label6
			// 
			this.label6.BackColor = System.Drawing.SystemColors.ControlDark;
			this.label6.Dock = System.Windows.Forms.DockStyle.Top;
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(518, 16);
			this.label6.TabIndex = 4;
			this.label6.Text = "Views";
			// 
			// tpStoredProcs
			// 
			this.tpStoredProcs.Controls.AddRange(new System.Windows.Forms.Control[] {
																						this.lvProcedures,
																						this.label5});
			this.tpStoredProcs.Location = new System.Drawing.Point(4, 25);
			this.tpStoredProcs.Name = "tpStoredProcs";
			this.tpStoredProcs.Size = new System.Drawing.Size(518, 296);
			this.tpStoredProcs.TabIndex = 2;
			this.tpStoredProcs.Text = "Stored Procedures";
			this.tpStoredProcs.Visible = false;
			// 
			// lvProcedures
			// 
			this.lvProcedures.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.lvProcedures.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																						   this.columnHeader13,
																						   this.columnHeader14,
																						   this.columnHeader15,
																						   this.columnHeader16});
			this.lvProcedures.Dock = System.Windows.Forms.DockStyle.Fill;
			this.lvProcedures.Font = new System.Drawing.Font("Verdana", 8.25F);
			this.lvProcedures.FullRowSelect = true;
			this.lvProcedures.GridLines = true;
			this.lvProcedures.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
			this.lvProcedures.Location = new System.Drawing.Point(0, 16);
			this.lvProcedures.MultiSelect = false;
			this.lvProcedures.Name = "lvProcedures";
			this.lvProcedures.Size = new System.Drawing.Size(518, 280);
			this.lvProcedures.TabIndex = 4;
			this.lvProcedures.View = System.Windows.Forms.View.Details;
			this.lvProcedures.Resize += new System.EventHandler(this.lvAll_Resize);
			this.lvProcedures.DoubleClick += new System.EventHandler(this.lvProcedures_DoubleClick);
			// 
			// columnHeader13
			// 
			this.columnHeader13.Text = "Database 1";
			this.columnHeader13.Width = 200;
			// 
			// columnHeader14
			// 
			this.columnHeader14.Text = "State";
			this.columnHeader14.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// columnHeader15
			// 
			this.columnHeader15.Text = "Action";
			this.columnHeader15.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// columnHeader16
			// 
			this.columnHeader16.Text = "Database 2";
			this.columnHeader16.Width = 200;
			// 
			// label5
			// 
			this.label5.BackColor = System.Drawing.SystemColors.ControlDark;
			this.label5.Dock = System.Windows.Forms.DockStyle.Top;
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(518, 16);
			this.label5.TabIndex = 5;
			this.label5.Text = "Stored Procedures";
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.lbLog});
			this.groupBox3.Dock = System.Windows.Forms.DockStyle.Bottom;
			this.groupBox3.Location = new System.Drawing.Point(0, 388);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(712, 100);
			this.groupBox3.TabIndex = 17;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "Log";
			// 
			// lbLog
			// 
			this.lbLog.Dock = System.Windows.Forms.DockStyle.Fill;
			this.lbLog.IntegralHeight = false;
			this.lbLog.Location = new System.Drawing.Point(3, 17);
			this.lbLog.Name = "lbLog";
			this.lbLog.Size = new System.Drawing.Size(706, 80);
			this.lbLog.TabIndex = 2;
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem3,
																					  this.menuItem4,
																					  this.menuItem5});
			this.menuItem1.Text = "System";
			// 
			// menuItem3
			// 
			this.menuItem3.Index = 0;
			this.menuItem3.Text = "About";
			this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
			// 
			// menuItem4
			// 
			this.menuItem4.Index = 1;
			this.menuItem4.Text = "-";
			// 
			// menuItem5
			// 
			this.menuItem5.Index = 2;
			this.menuItem5.Text = "Exit";
			this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 1;
			this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem6});
			this.menuItem2.Text = "Help";
			// 
			// menuItem6
			// 
			this.menuItem6.Index = 0;
			this.menuItem6.Text = "Visit DaBCoS Homepage";
			this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
			// 
			// mmMain
			// 
			this.mmMain.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																				   this.menuItem1,
																				   this.menuItem2});
			// 
			// FormMain
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
			this.ClientSize = new System.Drawing.Size(712, 504);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.groupBox1,
																		  this.splitter2,
																		  this.groupBox2,
																		  this.splitter1,
																		  this.groupBox3,
																		  this.sbMain,
																		  this.tbMain});
			this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Menu = this.mmMain;
			this.MinimumSize = new System.Drawing.Size(720, 530);
			this.Name = "FormMain";
			this.Text = "DaBCoS";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.FormMain_Closing);
			this.Load += new System.EventHandler(this.FormMain_Load);
			((System.ComponentModel.ISupportInitialize)(this.sbpMessages)).EndInit();
			this.groupBox2.ResumeLayout(false);
			this.groupBox1.ResumeLayout(false);
			this.tcMain.ResumeLayout(false);
			this.tpTables.ResumeLayout(false);
			this.tpFunctions.ResumeLayout(false);
			this.tpViews.ResumeLayout(false);
			this.tpStoredProcs.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		public FormMain() {
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();						
		}


		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing ) {
			if( disposing ) {
				if (components != null) {
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}


		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() {
			Application.Run(new FormMain());
		}


		private void tbMain_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) {
			if (e.Button == tbbConnect)	{ 
				ClearDisplay();
				ConnectSQLServer(databaseLeft);
				if (databaseLeft.Connected) ListDatabase(databaseLeft);
			}
			if (e.Button == tbbConnect2) {
				ClearDisplay();
				ConnectSQLServer(databaseRight);			
				if (databaseRight.Connected) ListDatabase(databaseRight);
			}
			if (e.Button == tbbDisconnect) { 
				DisconnectSQLServer(databaseLeft.Connection);
			}
			if (e.Button == tbbDisconnect2) {
				DisconnectSQLServer(databaseRight.Connection);
			}
			if (e.Button == tbbDatabase) {
				ClearDisplay();
				ListDatabase(databaseLeft);
			}
			if (e.Button == tbbDatabase2) {
				ClearDisplay();
				ListDatabase(databaseRight);
			}
			if (e.Button == tbbCompare)	{
				ClearDisplay();
				Compare();
			}
		}


		private void tmrCleanStatusBar_Tick(object sender, System.EventArgs e) {
			sbpMessages.Text = null;
		}


		/// <summary>
		/// Write a message to the status bar. The message will remain for 3 secs
		/// or until another message should appear
		/// </summary>
		/// <param name="sText">Message body</param>
		public void ShowInfoMessage(string sText) {
			tmrCleanStatusBar.Stop();
			tmrCleanStatusBar.Interval = 3000;
			sbpMessages.Text = sText;			
			lbLog.SelectedIndex = lbLog.Items.Add(DateTime.Now.ToLongTimeString() + ": " + sText);			
			tmrCleanStatusBar.Start();		
		}


		/// <summary>
		/// Connect to SQL Server. 
		/// </summary>
		/// <remarks>A login window dialog will appear automatically</remarks>
		/// <returns></returns>
		private bool ConnectSQLServer(SqlServer target) {
			bool bResult = false;

			try {
				wndLoginInfo = new FormLogin();								
				if (wndLoginInfo.ShowDialog(this) == DialogResult.OK) {
					wndLoginInfo.Hide();				
					this.Refresh();

					target.Server	= wndLoginInfo.Server;
					target.Login	= wndLoginInfo.Login;
					target.Password = wndLoginInfo.Password;

                    target.AuthenticationType = SqlAuthentication.SQLSever;
                    if (target.Login == "") target.AuthenticationType = SqlAuthentication.NT;
                    
					target.Connect();

					if (target.Connected) {						
						UpdateToolbarButtons(target.Connection);
						if (target == databaseLeft) {
							lblServerFirst.Text = target.Server; 							
							lblUserFirst.Text = target.Login;
							lblDBFirst.Text = target.Connection.Database.ToString();
							lblSource1.Text = String.Format("Source 1: {0}", target.VersionName);
						} else {
							lblServerSecond.Text = target.Server; 
							lblUserSecond.Text = target.Login;
							lblDBSecond.Text = target.Connection.Database.ToString();
							lblSource2.Text = String.Format("Source 2: {0}", target.VersionName);
						}
						bResult = true;
					} else {
						UpdateToolbarButtons(target.Connection);
						ShowInfoMessage("Connection failed.");
					}
				} 
			}			
			catch (Exception eGeneral) {
				UpdateToolbarButtons(target.Connection);
				ShowInfoMessage("Connection failed");
				MessageBox.Show(this, eGeneral.Message, "General error during connection", MessageBoxButtons.OK, MessageBoxIcon.Error);			
			} 
			finally {
				wndLoginInfo.Dispose();
			}

			return bResult;
		}


		/// <summary>
		/// Disconnect from a SQL Server
		/// </summary>
		private void DisconnectSQLServer(SqlConnection scTarget) {
			scTarget.Close();
			UpdateToolbarButtons(scTarget);
			ShowInfoMessage("Disconnected.");
		}


		/// <summary>
		/// Update the toolbar buttons
		/// </summary>
		/// <param name="scSource">SQL Connection to use to determine the buttons' state</param>
		private void UpdateToolbarButtons(SqlConnection scSource) {
			bool bOpen = (scSource.State == ConnectionState.Open);

			if (scSource == databaseLeft.Connection) {
				tbbConnect.Enabled = !bOpen;
				tbbDisconnect.Enabled = bOpen;
				tbbDatabase.Enabled = bOpen;
			}

			if (scSource == databaseRight.Connection) {
				tbbConnect2.Enabled = !bOpen;
				tbbDisconnect2.Enabled = bOpen;
				tbbDatabase2.Enabled = bOpen;
			}

			tbbCompare.Enabled = (tbbDisconnect.Enabled & tbbDisconnect2.Enabled);
		}


		/// <summary>
		/// List a let select a database
		/// </summary>
		/// <param name="scSource">Source connection</param>
		private void ListDatabase(SqlServer sdSource) {			
			ShowInfoMessage(String.Format("Reading available databases on {0}...", sdSource.Connection.DataSource));
			
			if (sdSource.Connection.State != ConnectionState.Open) sdSource.Connection.Open();			
			try {
				wndDatabaseSelection = new FormSelectDatabase(sdSource);			
						
				if (wndDatabaseSelection.ShowDialog(this) == DialogResult.OK) {				
					ShowInfoMessage(string.Format("Selected database {0} on {1}.", sdSource.Connection.Database, sdSource.Connection.DataSource));				
					if (sdSource == databaseLeft) {
						lblDBFirst.Text = sdSource.Connection.Database.ToString(); 
						foreach (TabPage tp in tcMain.TabPages) {
							foreach (Object c in tp.Controls) {
								if (c is ListView) {
									(c as ListView).Columns[0].Text = sdSource.Connection.Database.ToString();
								}
							}
						}
					} else {
						lblDBSecond.Text = sdSource.Connection.Database.ToString(); 
						foreach (TabPage tp in tcMain.TabPages) {
							foreach (Object c in tp.Controls) {
								if (c is ListView) {
									(c as ListView).Columns[3].Text = sdSource.Connection.Database.ToString();
								}
							}
						}
					}
				} else {
					ShowInfoMessage("Action cancelled.");					
				}
			} finally {
				if (wndDatabaseSelection != null)
					wndDatabaseSelection.Dispose();
			}
		}


		/// <summary>
		/// Compare two databases and show the differencies
		/// </summary>
		private void Compare() {								
			ShowInfoMessage("Starting compare...");	
			CompareTables();
			CompareViews();
			CompareStoredProcedures();
			CompareFunctions();

			ShowInfoMessage("Finished...");	
			pbState.Value = 0;
		}


		/// <summary>
		/// Compare tables
		/// </summary>
		private void CompareTables() {
			ArrayList alFirst, alSecond;
			ArrayList alColFirst, alColSecond;
			ListViewItem lviDummy;

			// Read first database tables
			ShowInfoMessage(String.Format("Reading available tables on {0}..{1}...", databaseLeft.Connection.DataSource, databaseLeft.Connection.Database));
			alFirst = databaseLeft.GetTables();

			// Read second database tables
			ShowInfoMessage(String.Format("Reading available tables on {0}..{1}...", databaseRight.Connection.DataSource, databaseRight.Connection.Database));
			alSecond = databaseRight.GetTables();

			// Compare databases
			ShowInfoMessage(String.Format("Found a total of {0} tables ({1} + {2})", alFirst.Count + alSecond.Count, alFirst.Count, alSecond.Count));
			ShowInfoMessage("Comparing tables and columns...");		
			pbState.Maximum = alFirst.Count + alSecond.Count;
			pbState.Value = 0;

			// Compare first database against the second
			lvTables.BeginUpdate();
			for(int i=0; i<alFirst.Count; i++) {
				pbState.Increment(1);
				lviDummy = new ListViewItem(alFirst[i].ToString());
				
				// Find existing and missing tables
				if (!(alSecond.Contains(alFirst[i]))) {
					lviDummy.BackColor = Color.Orange;
					lviDummy.SubItems.Add(">");
					lviDummy.SubItems.Add("?");
					lviDummy.SubItems.Add(alFirst[i].ToString());
				} else {
					// Load columns
					alColFirst = databaseLeft.GetColumns(alFirst[i].ToString());
					alColSecond = databaseRight.GetColumns(alSecond[alSecond.IndexOf(alFirst[i])].ToString());

					// Scan tables for structure differencies
					if (Utils.ListAreEqual(alColFirst, alColSecond)) {
						lviDummy.SubItems.Add("=");
						lviDummy.SubItems.Add("");
						lviDummy.SubItems.Add(alFirst[i].ToString()); 
					} else {
						lviDummy.BackColor = Color.OrangeRed;
						lviDummy.SubItems.Add("!");
						lviDummy.SubItems.Add("");
						lviDummy.SubItems.Add(alFirst[i].ToString()); 
					}
				}
				lvTables.Items.Add(lviDummy);
			}

			// Find tables in second database not yet scanned
			for(int i=0; i<alSecond.Count; i++) {
				pbState.Increment(1);
				if (!(alFirst.Contains(alSecond[i]))) {
					lviDummy = new ListViewItem(alSecond[i].ToString());
					lviDummy.BackColor = Color.DarkOrange;
					lviDummy.SubItems.Add("<");
					lviDummy.SubItems.Add("?");
					lviDummy.SubItems.Add(alSecond[i].ToString());
					lvTables.Items.Add(lviDummy);
				}
			}			
			lvTables.EndUpdate();
			pbState.Value = 0;
		}


		/// <summary>
		/// Compare Views
		/// </summary>
		private void CompareViews() {
			ArrayList alViewsFirst;
			ArrayList alViewsSecond;
			ListViewItem lviDummy;

			// Read first database views
			ShowInfoMessage(String.Format("Reading available views on {0}..{1}...", databaseLeft.Connection.DataSource, databaseLeft.Connection.Database));
			alViewsFirst = databaseLeft.GetViews();

			// Read second database views
			ShowInfoMessage(String.Format("Reading available views on {0}..{1}...", databaseRight.Connection.DataSource, databaseRight.Connection.Database));
			alViewsSecond = databaseRight.GetViews();
			
			// Compare Views
			ShowInfoMessage(String.Format("Found a total of {0} views ({1} + {2})", alViewsFirst.Count + alViewsSecond.Count, alViewsFirst.Count, alViewsSecond.Count));
			ShowInfoMessage("Comparing views...");		
			pbState.Maximum = alViewsFirst.Count + alViewsSecond.Count;
			pbState.Value = 0;

			// Compare first database against the second
			lvViews.BeginUpdate();
			for(int i=0; i<alViewsFirst.Count; i++) {
				pbState.Increment(1);
				lviDummy = new ListViewItem(alViewsFirst[i].ToString());
				
				// Find existing and missing views
				if (!(alViewsSecond.Contains(alViewsFirst[i]))) {
					lviDummy.BackColor = Color.Orange;
					lviDummy.SubItems.Add(">");
					lviDummy.SubItems.Add("?");
					lviDummy.SubItems.Add(alViewsFirst[i].ToString());
				} else {
					// Load view definitions
					string sViewDef1 = databaseLeft.GetObjectDefinition(alViewsFirst[i].ToString());
					string sViewDef2 = databaseRight.GetObjectDefinition(alViewsSecond[alViewsSecond.IndexOf(alViewsFirst[i])].ToString());
				
					// Clean code
					sViewDef1 = Utils.PureText(sViewDef1);
					sViewDef2 = Utils.PureText(sViewDef2);

					// Compare view definitions
					if (sViewDef1.GetHashCode() == sViewDef2.GetHashCode()) {
						if ((sViewDef1 != string.Empty) && (sViewDef2 != string.Empty)) {
							lviDummy.SubItems.Add("=");
							lviDummy.SubItems.Add("");
						} else {
							lviDummy.BackColor = Color.DarkGoldenrod;
							lviDummy.SubItems.Add("?");
							lviDummy.SubItems.Add("?");								
						}
					} else {
						lviDummy.BackColor = Color.OrangeRed;
						lviDummy.SubItems.Add("!");
						lviDummy.SubItems.Add("?");
					}
					
					lviDummy.SubItems.Add(alViewsFirst[i].ToString()); 
				}
				lvViews.Items.Add(lviDummy);
			}

			// Find views in second database not yet scanned
			for(int i=0; i<alViewsSecond.Count; i++) {
				pbState.Increment(1);
				if (!(alViewsFirst.Contains(alViewsSecond[i]))) {
					lviDummy = new ListViewItem(alViewsSecond[i].ToString());
					lviDummy.BackColor = Color.DarkOrange;
					lviDummy.SubItems.Add("<");
					lviDummy.SubItems.Add("?");
					lviDummy.SubItems.Add(alViewsSecond[i].ToString());
					lvViews.Items.Add(lviDummy);
				}
			}			
			lvViews.EndUpdate();
			pbState.Value = 0;
		}


		/*
		 * Compare Stored Procedures
		 */
		private void CompareStoredProcedures() {
			ArrayList alProcsFirst;
			ArrayList alProcsSecond;
			ListViewItem lviDummy;

			// Read first database procedures
			ShowInfoMessage(String.Format("Reading available stored procedures on {0}..{1}...", databaseLeft.Connection.DataSource, databaseLeft.Connection.Database));
			alProcsFirst = databaseLeft.GetStoredProcedures();

			// Read second database procedures
			ShowInfoMessage(String.Format("Reading available stored procedures on {0}..{1}...", databaseRight.Connection.DataSource, databaseRight.Connection.Database));
			alProcsSecond = databaseRight.GetStoredProcedures();
			
			// Compare procedures
			ShowInfoMessage(String.Format("Found a total of {0} stored procedures ({1} + {2})", alProcsFirst.Count + alProcsSecond.Count, alProcsFirst.Count, alProcsSecond.Count));
			ShowInfoMessage("Comparing stored procedures...");		
			pbState.Maximum = alProcsFirst.Count + alProcsSecond.Count;
			pbState.Value = 0;
		
			// Compare first database against the second
			lvProcedures.BeginUpdate();
			for(int i=0; i<alProcsFirst.Count; i++) {
				pbState.Increment(1);
				lviDummy = new ListViewItem(alProcsFirst[i].ToString());
				
				// Find existing and missing procedures
				if (!(alProcsSecond.Contains(alProcsFirst[i]))) {
					lviDummy.BackColor = Color.Orange;
					lviDummy.SubItems.Add(">");
					lviDummy.SubItems.Add("?");
					lviDummy.SubItems.Add(alProcsFirst[i].ToString());
				} else {
					// Load procedures definitions
					string sProcDef1 = databaseLeft.GetObjectDefinition(alProcsFirst[i].ToString());
					string sProcDef2 = databaseRight.GetObjectDefinition(alProcsSecond[alProcsSecond.IndexOf(alProcsFirst[i])].ToString());
				
					// Clean Code
					sProcDef1 = Utils.PureText(sProcDef1);
					sProcDef2 = Utils.PureText(sProcDef2);

					// Compare procedure definitions
					if (sProcDef1.GetHashCode() == sProcDef2.GetHashCode()) {
						if ((sProcDef1 != string.Empty) && (sProcDef2 != string.Empty)) {
							lviDummy.SubItems.Add("=");
							lviDummy.SubItems.Add("");
						} else {
							lviDummy.BackColor = Color.DarkGoldenrod;
							lviDummy.SubItems.Add("?");
							lviDummy.SubItems.Add("?");								
						}
					} else {
						lviDummy.BackColor = Color.OrangeRed;
						lviDummy.SubItems.Add("!");
						lviDummy.SubItems.Add("?");
					}
					
					lviDummy.SubItems.Add(alProcsFirst[i].ToString()); 
				}
				lvProcedures.Items.Add(lviDummy);
			}

			// Find procedures in second database not yet scanned
			for(int i=0; i<alProcsSecond.Count; i++) {
				pbState.Increment(1);
				if (!(alProcsFirst.Contains(alProcsSecond[i]))) {
					lviDummy = new ListViewItem(alProcsSecond[i].ToString());
					lviDummy.BackColor = Color.DarkOrange;
					lviDummy.SubItems.Add("<");
					lviDummy.SubItems.Add("?");
					lviDummy.SubItems.Add(alProcsSecond[i].ToString());
					lvProcedures.Items.Add(lviDummy);
				}
			}			
			lvProcedures.EndUpdate();
			pbState.Value = 0;		
		}


		/*
		 * Compare Functions
		 */
		private void CompareFunctions() {
			ArrayList alFuncsFirst;
			ArrayList alFuncsSecond;
			ListViewItem lviDummy;

			// Read first database functions
			ShowInfoMessage(String.Format("Reading available functions on {0}..{1}...", databaseLeft.Connection.DataSource, databaseLeft.Connection.Database));
			alFuncsFirst = databaseLeft.GetFunctions();

			// Read second database functions
			ShowInfoMessage(String.Format("Reading available functions on {0}..{1}...", databaseRight.Connection.DataSource, databaseRight.Connection.Database));
			alFuncsSecond = databaseRight.GetFunctions();
			
			// Compare functions
			ShowInfoMessage(String.Format("Found a total of {0} functions ({1} + {2})", alFuncsFirst.Count + alFuncsSecond.Count, alFuncsFirst.Count, alFuncsSecond.Count));
			ShowInfoMessage("Comparing functions...");		
			pbState.Maximum = alFuncsFirst.Count + alFuncsSecond.Count;
			pbState.Value = 0;
		
			// Compare first database against the second
			lvFunctions.BeginUpdate();
			for(int i=0; i<alFuncsFirst.Count; i++) {
				pbState.Increment(1);
				lviDummy = new ListViewItem(alFuncsFirst[i].ToString());
				
				// Find existing and missing functions
				if (!(alFuncsSecond.Contains(alFuncsFirst[i]))) {
					lviDummy.BackColor = Color.Orange;
					lviDummy.SubItems.Add(">");
					lviDummy.SubItems.Add("?");
					lviDummy.SubItems.Add(alFuncsFirst[i].ToString());
				} else {
					// Load functions definitions
					string sFuncDef1 = databaseLeft.GetObjectDefinition(alFuncsFirst[i].ToString());
					string sFuncDef2 = databaseRight.GetObjectDefinition(alFuncsSecond[alFuncsSecond.IndexOf(alFuncsFirst[i])].ToString());
				
					// Clean Code
					sFuncDef1 = Utils.PureText(sFuncDef1);
					sFuncDef2 = Utils.PureText(sFuncDef2);

					// Compare functions definitions
					if (sFuncDef1.GetHashCode() == sFuncDef2.GetHashCode()) {
						if ((sFuncDef1 != string.Empty) && (sFuncDef2 != string.Empty)) {
							lviDummy.SubItems.Add("=");
							lviDummy.SubItems.Add("");
						} else {
							lviDummy.BackColor = Color.DarkGoldenrod;
							lviDummy.SubItems.Add("?");
							lviDummy.SubItems.Add("?");								
						}
					} else {
						lviDummy.BackColor = Color.OrangeRed;
						lviDummy.SubItems.Add("!");
						lviDummy.SubItems.Add("?");
					}
					
					lviDummy.SubItems.Add(alFuncsFirst[i].ToString()); 
				}

				lvFunctions.Items.Add(lviDummy);
			}

			// Find functions in second database not yet scanned
			for(int i=0; i<alFuncsSecond.Count; i++) {
				pbState.Increment(1);
				if (!(alFuncsFirst.Contains(alFuncsSecond[i]))) {
					lviDummy = new ListViewItem(alFuncsSecond[i].ToString());
					lviDummy.BackColor = Color.DarkOrange;
					lviDummy.SubItems.Add("<");
					lviDummy.SubItems.Add("?");
					lviDummy.SubItems.Add(alFuncsSecond[i].ToString());
					lvFunctions.Items.Add(lviDummy);
				}
			}			
			lvFunctions.EndUpdate();
			pbState.Value = 0;		
		}


		/// <summary>
		/// Handles Double-Click event on the Tables ListView
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void lvTables_DoubleClick(object sender, System.EventArgs e) {
			if (lvTables.SelectedItems != null) {				
				ListViewItem lviDummy;
				string sLeftTable = lvTables.SelectedItems[0].SubItems[0].Text;
				string sRightTable = lvTables.SelectedItems[0].SubItems[3].Text;

				ArrayList alLeft = databaseLeft.GetColumns(sLeftTable);
				ArrayList alRight = databaseRight.GetColumns(sRightTable);

				wndDatabaseInfo = new FormDetail();
				wndDatabaseInfo.Text = String.Format("Details on table {0}", sLeftTable);
				wndDatabaseInfo.lvDetails.Columns[0].Text = String.Format("{0}.{1}..{2}", databaseLeft.Connection.DataSource, databaseLeft.Connection.Database, sLeftTable);
				wndDatabaseInfo.lvDetails.Columns[1].Text = String.Format("{0}.{1}..{2}", databaseRight.Connection.DataSource, databaseRight.Connection.Database, sRightTable);

				wndDatabaseInfo.tpSource1.Text = "not available";
				wndDatabaseInfo.tpSource2.Text = "not available";

				int iMaxCol = alLeft.Count;
				if (alRight.Count > iMaxCol) iMaxCol = alRight.Count;

				for (int i=0; i<iMaxCol; i++) {
					if (i<alLeft.Count) {
						lviDummy = new ListViewItem(alLeft[i].ToString());
					} else {
						lviDummy = new ListViewItem(string.Empty);
					}
					wndDatabaseInfo.lvDetails.Items.Add(lviDummy);
				}

				for (int i=0; i<iMaxCol; i++) {				
					lviDummy = wndDatabaseInfo.lvDetails.Items[i];
					if (i<alRight.Count) {
						lviDummy.SubItems.Add(alRight[i].ToString());
					} else {
						lviDummy.SubItems.Add(string.Empty);
					}
					if (lviDummy.SubItems[0].ToString() != lviDummy.SubItems[1].ToString()) {
						lviDummy.BackColor = Color.Orange;
					}
				}

				wndDatabaseInfo.ShowDialog(this);
				wndDatabaseInfo.Dispose();
			}
		}


		/// <summary>
		/// Initialize Main Form
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void FormMain_Load(object sender, System.EventArgs e) {
			Text = Application.ProductName + " v " + Application.ProductVersion;
			
			pbDB1.Image		= pbDB2.Image		= ilMisc.Images[0];
			pbUser1.Image	= pbUser2.Image		= ilMisc.Images[1];
			pbTable1.Image	= pbTable2.Image	= ilMisc.Images[2];

			Utils.ReadPersistentFormData(this);
			
			ResizeColumns(lvTables);
			ResizeColumns(lvViews);
			ResizeColumns(lvProcedures);
			ResizeColumns(lvFunctions);

			databaseLeft = new SqlServer();
			databaseLeft.SetLogger(new DaBCoS.Engine.LogFunction(ShowInfoMessage));

			databaseRight = new SqlServer();
			databaseRight.SetLogger(new DaBCoS.Engine.LogFunction(ShowInfoMessage));

			ShowInfoMessage(Application.ProductName + " v " + Application.ProductVersion + " (c) 2002 " + Application.CompanyName);
			ShowInfoMessage("This application is released under the GNU GPL license.");
			ShowInfoMessage("Visit http://sourceforge.net/projects/dabcos to have more info and support.");
		}


		/// <summary>
		/// Resize the columns of ListView accordingly to the form size
		/// </summary>
		/// <param name="lvSource">ListView which has columns to be resized</param>
		private void ResizeColumns(ListView lvSource) {
			int iTotWidth = lvSource.Width;
			
			lvSource.BeginUpdate();
			lvSource.Columns[0].Width = (iTotWidth * 40 / 100);
			lvSource.Columns[1].Width = (iTotWidth * 10 / 100);
			lvSource.Columns[2].Width = (iTotWidth * 10 / 100);
			lvSource.Columns[3].Width = (iTotWidth * 40 / 100);		
			lvSource.EndUpdate();			
		}

				
		/// <summary>
		/// Clear ListViews
		/// </summary>
		public void ClearDisplay() {			
			foreach (TabPage tp in tcMain.TabPages) {
				foreach (Object c in tp.Controls) {
					if (c is ListView) {
						(c as ListView).Items.Clear();
						(c as ListView).Update();
					}
				}
			}
		}

		private void ShowSourceCode(string sLeftView, string sLeftViewDef, string sRightView, string sRightViewDef) {
			ListViewItem lviDummy;
			string sDummy;

			if (sLeftViewDef == string.Empty) {
				sLeftViewDef = "Cannot read source code.\rThe object can be missing, the code may me crypted or database connection has been lost.";
			}

			if (sRightViewDef == string.Empty) {
				sRightViewDef = "Cannot read source code.\rThe object can be missing, the code may me crypted or database connection has been lost.";
			}

			wndDatabaseInfo = new FormDetail();
			wndDatabaseInfo.Text = String.Format("Details on procedure {0}", sLeftView);

			wndDatabaseInfo.lvDetails.Columns[0].Text = String.Format("{0}.{1}..{2}", databaseLeft.Connection.DataSource, databaseLeft.Connection.Database, sLeftView);
			wndDatabaseInfo.lvDetails.Columns[1].Text = String.Format("{0}.{1}..{2}", databaseRight.Connection.DataSource, databaseRight.Connection.Database, sRightView);											

			wndDatabaseInfo.tpSource1.Text = String.Format("{0}.{1}..{2}", databaseLeft.Connection.DataSource, databaseLeft.Connection.Database, sLeftView);
			wndDatabaseInfo.rtbSource1.Text = sLeftViewDef;

			wndDatabaseInfo.tpSource2.Text = String.Format("{0}.{1}..{2}", databaseRight.Connection.DataSource, databaseRight.Connection.Database, sRightView);											
			wndDatabaseInfo.rtbSource2.Text = sRightViewDef;
				
			// Store first definition line by line
			StringCollection scLeftLines = new StringCollection();
			if (sLeftViewDef != null) {
				sLeftViewDef = sLeftViewDef.Replace("\r\n", "\n");
				scLeftLines.AddRange(sLeftViewDef.Split(new Char[] {'\r', '\n'}));
			}

			// Store second definition line by line
			StringCollection scRightLines = new StringCollection();
			if (sRightViewDef != null) {
				sRightViewDef = sRightViewDef.Replace("\r\n", "\n");
				scRightLines.AddRange(sRightViewDef.Split(new Char[] {'\r', '\n'}));
			}

			// Compare definitions
			int iMaxCol = scLeftLines.Count;
			if (scRightLines.Count > iMaxCol) iMaxCol = scRightLines.Count;

			for (int i=0; i<iMaxCol; i++) {
				if (i<scLeftLines.Count) {
					sDummy = scLeftLines[i].Replace("\t", "    ");
					lviDummy = new ListViewItem(sDummy);
				} else {
					lviDummy = new ListViewItem(string.Empty);
				}
				wndDatabaseInfo.lvDetails.Items.Add(lviDummy);
			}

			for (int i=0; i<iMaxCol; i++) {				
				lviDummy = wndDatabaseInfo.lvDetails.Items[i];
				if (i<scRightLines.Count) {
					sDummy = scRightLines[i].Replace("\t", "    ");
					lviDummy.SubItems.Add(sDummy);
				} else {
					lviDummy.SubItems.Add(string.Empty);
				}
				if (Utils.PureText(lviDummy.SubItems[0].ToString()) != Utils.PureText(lviDummy.SubItems[1].ToString())) {
					lviDummy.BackColor = Color.Orange;
				}
			}

			wndDatabaseInfo.ShowDialog(this);
			wndDatabaseInfo.Dispose();
		}

		/// <summary>
		/// Handles Double-Click event on the Views ListView
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void lvViews_DoubleClick(object sender, System.EventArgs e) {			
			if (lvViews.SelectedItems != null) {								
				// Load View names
				string sLeftView	= lvViews.SelectedItems[0].SubItems[0].Text;
				string sRightView	= lvViews.SelectedItems[0].SubItems[3].Text;

				// Load View definitions
				string sLeftViewDef		= databaseLeft.GetObjectDefinition(sLeftView).Trim();
				string sRightViewDef	= databaseRight.GetObjectDefinition(sRightView).Trim();

				// Show Info
				ShowSourceCode(sLeftView, sLeftViewDef, sRightView, sRightViewDef);
			}		
		}

		
		private void lvProcedures_DoubleClick(object sender, System.EventArgs e) {
			if (lvProcedures.SelectedItems != null) {								
				// Load Procedure names
				string sLeftProc	= lvProcedures.SelectedItems[0].SubItems[0].Text;
				string sRightProc	= lvProcedures.SelectedItems[0].SubItems[3].Text;

				// Load Procedure definitions
				string sLeftProcDef		= databaseLeft.GetObjectDefinition(sLeftProc).Trim();
				string sRightProcDef	= databaseRight.GetObjectDefinition(sRightProc).Trim();

				// Show Info
				ShowSourceCode(sLeftProc, sLeftProcDef, sRightProc, sRightProcDef);
			}				
		}

		
		private void lvFunctions_DoubleClick(object sender, System.EventArgs e) {
			if (lvProcedures.SelectedItems != null) {								
				// Load Function names
				string sLeftFunc	= lvFunctions.SelectedItems[0].SubItems[0].Text;
				string sRightFunc	= lvFunctions.SelectedItems[0].SubItems[3].Text;

				// Load Function definitions
				string sLeftFuncDef		= databaseLeft.GetObjectDefinition(sLeftFunc).Trim();
				string sRightFuncDef	= databaseRight.GetObjectDefinition(sRightFunc).Trim();

				// Show Info
				ShowSourceCode(sLeftFunc, sLeftFuncDef, sRightFunc, sRightFuncDef);
			}						
		}

		private void lvAll_Resize(object sender, System.EventArgs e) {
			ResizeColumns(sender as ListView);
		}

		private void sc_InfoMessage(object sender, System.Data.SqlClient.SqlInfoMessageEventArgs e) {
			string sConnectionName = "";
			SqlConnection scDummy;

			if (sender is SqlConnection) {
				scDummy = (SqlConnection)sender; 
				if (scDummy == databaseLeft.Connection) {
					sConnectionName = "Source 1";
				} else {
					sConnectionName = "Source 2";
				}
			}
			
			ShowInfoMessage(String.Format("[{0}: " + e.Message + "].", sConnectionName));
		}

		private void sc_StateChange(object sender, System.Data.StateChangeEventArgs e) {
			string sConnectionName = "";
			SqlConnection scDummy;

			if (sender is SqlConnection) {
				scDummy = (SqlConnection)sender; 
				if (scDummy == databaseLeft.Connection) {
					sConnectionName = "Source 1";
				} else {
					sConnectionName = "Source 2";
				}
			}

			ShowInfoMessage(String.Format("[{0}: " + e.CurrentState.ToString() + "].", sConnectionName));
		}

		private void menuItem6_Click(object sender, System.EventArgs e) {
			System.Diagnostics.Process.Start("http://www.davidemauri.it/dabcos");
		}

		private void menuItem3_Click(object sender, System.EventArgs e) {
			wndAbout = new FormAbout();
			wndAbout.ShowDialog(this);
			wndAbout.Close();
			wndAbout.Dispose();
		}

		private void menuItem5_Click(object sender, System.EventArgs e) {
			Application.Exit();
		}

		private void FormMain_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
			Utils.WritePersistentFormData(this);
		}
	}
}
